package com.sskj.sys.repository;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.sskj.core.repository.GenericRepository;
import com.sskj.sys.domain.entity.MediaEntity;

public interface MediaRepository extends GenericRepository<MediaEntity, String> {

	@Transactional
	@Modifying(clearAutomatically = true)
	@Query("update MediaEntity x set x.associatedid=?1 where x.id in (?2)")
	void updateMedia(String associatedid, List<String> ids);

	@Transactional
	@Modifying(clearAutomatically = true)
	@Query("delete MediaEntity x where x.associatedid=?1 and x.id not in (?2)")
	void delMedia(String associatedid, List<String> ids);

	@Query("SELECT r FROM MediaEntity r " + " where r.associatedid = ?1  order by r.createdTime asc")
	List<MediaEntity> queryPic(String associatedid);

}
